package controller.webservice.bootstrap;

import java.io.IOException;

import manager.StudentMgr;
import controller.validator.StudentValidator;
import exception.InputValidationErrors;

/**
 * Validates and loads student CSV.
 * 
 * @author huangjm.2012, jaslin.wee.2012, sheryl.tay.2012
 * 
 */
public class StudentCsvLoader extends CsvLoader {

	private StudentMgr studentMgr;

	StudentCsvLoader(String pathToFile) throws IOException {
		super(pathToFile);
		studentMgr = new StudentMgr();
	}

	@Override
	boolean loadRow() throws InputValidationErrors {
		String userId = getValue("userid");
		String password = getValue("password");
		String name = getValue("name");
		String school = getValue("school");
		String edollarStr = getValue("edollar");

		StudentValidator validator = new StudentValidator(userId, password,
				name, school, edollarStr);
		validator.performValidationBeforeAdding();

		return studentMgr.addStudent(validator.getStudent());

	}

}
